package com.xs.partnermatching.easyExcel;

import com.alibaba.excel.EasyExcel;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author xsf
 * @ClassName ImportXingQiuUser
 * @date 2024/10/07
 * @version: 1.0
 * @description 导入星球用户到数据库
 */
public class ImportXingQiuUser {
    public static void main(String[] args) {
        // Excel数据文件放在电脑上，能够找到的路径
        String fileName = "doc/testExcel.xlsx";
        List<XingQiuTableUserInfo> userInfoList = EasyExcel.read(fileName).head(XingQiuTableUserInfo.class).sheet().doReadSync();
        System.out.println("总数 = " + userInfoList.size());
        // 根据用户名对用户信息进行分组，过滤掉用户名为空的记录
        Map<String, List<XingQiuTableUserInfo>> listMap =
                userInfoList.stream()
                        .filter(userInfo -> StringUtils.isNotEmpty(userInfo.getUserName()))
                        .collect(Collectors.groupingBy(XingQiuTableUserInfo::getUserName));
        // 遍历分组后的用户信息，查找重复的昵称
        for (Map.Entry<String, List<XingQiuTableUserInfo>> stringListEntry : listMap.entrySet()) {
            if (stringListEntry.getValue().size() > 1) {
                System.out.println("userName = " + stringListEntry.getKey());
                System.out.println("1");
            }
        }
        System.out.println("不重复昵称 = " + listMap.keySet().size());
    }
}
